package person.bing.fbcloud.leetcode;

/**
 * @author: mengfanbing
 * @date: 2020/9/28 10:29
 */
public class Q53 {
    public static void main(String[] args) {
        int[] test = {-2,1,-3,4,-1,2,1,-5,4};
        int i = maxSubArray(test);
        System.out.println(i);

    }
    public static int maxSubArray(int[] nums) {
        int pre = 0;int maxAns = nums[0];
        for (int num:nums){
            pre = Math.max(pre+num,num);
            maxAns = Math.max(pre,maxAns);
        }
        return maxAns;
    }
}
